package com.xmb.quick.util;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

public class MD5 {

	public static String toMD5PWD(String username, String pwd) {

		String hashAlgorithmName = "MD5";// 加密方式

		ByteSource salt = ByteSource.Util.bytes(username);// 以账号作为盐值

		int hashIterations = 2;// 加密2次

		SimpleHash hash = new SimpleHash(hashAlgorithmName, pwd, salt, hashIterations);

		return hash.toString();
	}

	public static String encode(String str) {

		String hashAlgorithmName = "MD5";// 加密方式

		SimpleHash hash = new SimpleHash(hashAlgorithmName, str, null, 1);

		return hash.toString();
	}

	public static void main(String[] args) {
		System.out.println(toMD5PWD("13650529233", "529233"));
	}
}
